export function RenderData() {
    if(!RenderData.init){
        console.error('在实例化分页器之前,应当显执行Pagenator.config()');
        return ;
    }
    this.startIndex = RenderData.startIndex;
    this.endIndex = RenderData.endIndex;
    this.data = RenderData.data;
}

RenderData.config = function({startIndex,endIndex,data}){
    RenderData.startIndex = startIndex;
    RenderData.endIndex = endIndex;
    RenderData.data = data;
    RenderData.init = true;
}

RenderData.prototype.setStartEndIndex = function(startIndex,endIndex){
    this.startIndex = startIndex;
    this.endIndex = endIndex;
}

RenderData.prototype.createData = function (callback,contianer){
    var html = "";
    for (let i = this.startIndex; i <= this.endIndex; i++) {
        if (this.data[i]){
            html += this.createRow(callback,this.data[i]);
        }else{
            html += this.createRow(callback);
        }
    }

    contianer.innerHTML = html;
}


RenderData.prototype.createRow = function (callback,data) {
    return callback(data);
}

RenderData.prototype.virtualUpdate = function(callback,oldData){
    var newData = this.data.slice(this.startIndex,this.endIndex+1)
    callback(oldData,newData);
}

RenderData.prototype.virtualRenderDom = function(callback,oldData,newData){
    callback(oldData,newData);
}

RenderData.prototype.setDataOrigin = function(newData){
    this.data = newData;
}